package belf.migrate.engine.job.model.sql;

import belf.migrate.api.common.DbConstant;
import belf.migrate.api.table.schema.ColumnMetaData;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Locale;

@Data
@NoArgsConstructor
public class ColumnResult {

    private String columnName;

    private String columnType;

    private String comment;

    private String tableName;

    @JsonIgnore
    private Integer sort;

    public ColumnResult(ColumnMetaData columnMetaData) {
        this.columnName = columnMetaData.getColumnName().toUpperCase(Locale.ROOT);
        this.columnType = columnMetaData.getColumnTypeName();
        this.comment = columnMetaData.getColumnComment();
        this.tableName = columnMetaData.getTableName();
        if (columnMetaData.isPrimaryKey()) {
            this.sort = 0;
        } else if (DbConstant.DATETIME_TYPES.contains(columnMetaData.getColumnTypeName().toLowerCase(Locale.ROOT))) {
            this.sort = 1;
        } else {
            this.sort = 2;
        }
    }
}
